﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Metro;
using DevComponents.DotNetBar;
using System.IO;
using System.Xml;
using System.Diagnostics;
namespace APP
{
    public partial class Form1 : MetroAppForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DevComponents.DotNetBar.Metro.eMetroTileColor[] Color=new DevComponents.DotNetBar.Metro.eMetroTileColor[23];
            Color[0] = DevComponents.DotNetBar.Metro.eMetroTileColor.Default;
            Color[1] = DevComponents.DotNetBar.Metro.eMetroTileColor.Azure;
            Color[2] = DevComponents.DotNetBar.Metro.eMetroTileColor.Blue;
            Color[3] = DevComponents.DotNetBar.Metro.eMetroTileColor.Blueish;
            Color[4] = DevComponents.DotNetBar.Metro.eMetroTileColor.Coffee;
            Color[5] = DevComponents.DotNetBar.Metro.eMetroTileColor.DarkBlue;
            Color[6] = DevComponents.DotNetBar.Metro.eMetroTileColor.DarkGreen;
            Color[7] = DevComponents.DotNetBar.Metro.eMetroTileColor.DarkOlive;
            Color[8] = DevComponents.DotNetBar.Metro.eMetroTileColor.Gray;
            Color[9] = DevComponents.DotNetBar.Metro.eMetroTileColor.Green;
            Color[10] = DevComponents.DotNetBar.Metro.eMetroTileColor.Magenta;
            Color[11] = DevComponents.DotNetBar.Metro.eMetroTileColor.Maroon;
            Color[12] = DevComponents.DotNetBar.Metro.eMetroTileColor.MaroonWashed;
            Color[13] = DevComponents.DotNetBar.Metro.eMetroTileColor.Olive;
            Color[14] = DevComponents.DotNetBar.Metro.eMetroTileColor.Orange;
            Color[15] = DevComponents.DotNetBar.Metro.eMetroTileColor.Plum;
            Color[16] = DevComponents.DotNetBar.Metro.eMetroTileColor.PlumWashed;
            Color[17] = DevComponents.DotNetBar.Metro.eMetroTileColor.RedOrange;
            Color[18] = DevComponents.DotNetBar.Metro.eMetroTileColor.RedViolet;
            Color[19] = DevComponents.DotNetBar.Metro.eMetroTileColor.Rust;
            Color[20] = DevComponents.DotNetBar.Metro.eMetroTileColor.Teal;
            Color[21] = DevComponents.DotNetBar.Metro.eMetroTileColor.Yellow;
            Color[22] = DevComponents.DotNetBar.Metro.eMetroTileColor.Yellowish;
            //MessageBox.Show(Environment.CurrentDirectory);
            DirectoryInfo dir = new DirectoryInfo(Environment.CurrentDirectory+"\\APPLib");
            foreach (DirectoryInfo di in dir.GetDirectories())
            {
                string s = "";
                String Foder = Environment.CurrentDirectory + "\\APPLib" + "\\" + di.ToString();
                String FullPath = Environment.CurrentDirectory + "\\APPLib" + "\\" + di.ToString() + "\\cfg.xml";
                XmlDocument doc = new XmlDocument();
                if (File.Exists(FullPath))
                {
                    String[] Info= new String[6];
                    doc.Load(FullPath);
                    XmlNodeReader reader = new XmlNodeReader(doc);
                    while (reader.Read())
                    {
                        
                        switch (reader.NodeType)
                        {
                            case XmlNodeType.Element:
                                s = reader.Name;
                                break;
                            case XmlNodeType.Text:
                                if (s.Equals("APPNameLine1"))
                                    Info[0]=reader.Value;
                                else if (s.Equals("APPNameLine2"))
                                    Info[1]=reader.Value;
                                else if (s.Equals("APPIcon"))
                                    Info[2]=reader.Value;
                                else if (s.Equals("APPAuthor"))
                                    Info[3] = reader.Value;
                                else if (s.Equals("ItemColor"))
                                    Info[4] = reader.Value;
                                else if (s.Equals("Path"))
                                    Info[5] = reader.Value;
                                break;
                        }
                    }
                    DevComponents.DotNetBar.Metro.MetroTileItem metroTileItem1 = new DevComponents.DotNetBar.Metro.MetroTileItem();
                    metroTileItem1.Image = Image.FromFile(Foder + "\\" + Info[2]);
                    metroTileItem1.TileColor = Color[Convert.ToInt16(Info[4])];
                    metroTileItem1.Text = "<div style=\" font-family:微软雅黑 ; font-weight:800\"><font size=\"+4\">" + Info[0] + "<br/>" + Info[1] + "</font></div>";
                    metroTileItem1.TitleText = Info[3];
                    metroTileItem1.Click += new System.EventHandler((object sender1, EventArgs e1) => 
                    {
                        if (File.Exists(Foder + Info[5]))
                            Process.Start(Foder + Info[5]);
                        else
                            MessageBox.Show("检测不到" + Info[5] + "，cfg.xml路径设置错误，请检查！", "路径错误！", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                    metroTileItem1.TitleTextAlignment = System.Drawing.ContentAlignment.BottomRight;
                    this.itemContainer1.SubItems.AddRange(new DevComponents.DotNetBar.BaseItem[] { metroTileItem1 });
                }
            }
        }

        private void metroTileItem1_Click(object sender, EventArgs e)
        {

        }
    }
}
